﻿/*
This file is the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. https://go.microsoft.com/fwlink/?LinkId=518007
*/

var gulp = require('gulp');

gulp.task('default', function () {
    // place code for your default task here
    "use strict";
    var gulp = require("gulp"),
        rimraf = require("rimraf"),
        concat = require("gulp-concat"),
        cssmin = require("gulp-cssmin"),
        uglify = require("gulp-uglify")

    var paths = {
        webroot: "./wwwroot/"
    };
    paths.node_modules_libs = [
        'node_modules/jquery/dist/jquery.js',
        'node_modules/bootstrap/dist/js/bootstrap.js',
    ]
    paths.lib = paths.webroot + 'lib/*.js';
    paths.js = paths.webroot + "js/**/*.js";
    paths.minJs = paths.webroot + "js/**/*.min.js";
    paths.concatJsDest = paths.webroot + "js/site.min.js";

    gulp.task('lib', function () {     //复制npm包到web root中
        gulp.src(paths.node_modules_libs).pipe(gulp.dest(paths.webroot + 'lib'))
    });

    gulp.task("clean:js", function (cb) {   //清理压缩后的js文件
        rimraf(paths.concatJsDest, cb);
    });
    gulp.task("min:js", function () {  //将需要的js压缩并合并成一个文件以减少http请求数
        gulp.src([paths.js, "!" + paths.minJs, paths.lib], { base: "." }).pipe(concat(paths.concatJsDest))
            .pipe(uglify())
            .pipe(gulp.dest("."));
    });
});